package com.sanrenzu.everybodytv.ui.live;

import android.os.Handler;
import android.os.Looper;

import com.sanrenzu.everybodytv.bean.gy.LiveBean;
import com.sanrenzu.everybodytv.bean.gy.LiveDataBean;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/9/6 0006.
 */
public class LivePresenter implements LiveContract.Presenter{
    private LiveContract.View view;
    private  LiveContract.Model model;
    public LivePresenter(LiveContract.View view){
        this.view=view;
        model=new LiveModel();
    }
    @Override
    public void getData() {
    model.getData(new Callback<LiveBean>() {
        @Override
        public void onResponse(Call<LiveBean> call, Response<LiveBean> response) {
            LiveBean liveBean=response.body();
            final List<LiveDataBean> liveDataBeanList=liveBean.getData();
            Handler handler=new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                  view.onGetDataSuccess(liveDataBeanList);
                }
            });
        }

        @Override
        public void onFailure(Call<LiveBean> call, Throwable t) {
            Handler handler=new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    view.onGetDataFail("数据加载失败");
                }
            });
        }
    });
    }
}
